<template>
  <div class="app-container">
    <!-- 高级查询 -->
    <el-form v-show="searchVisible" ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item label="合同编码:" prop="contractCode">
        <el-input v-model="queryParams.contractCode" size="small" placeholder="请输入合同编码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="合同名称:" prop="contractName">
        <el-input v-model="queryParams.contractName" size="small" placeholder="请输入合同名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
      </el-col>
      <right-toolbar :show-search.sync="searchVisible" @queryTable="handleQuery" />
    </el-row>

    <!-- 数据列表 -->
    <el-table v-loading="loading" :data="page.records" :cell-style="cellStyle" highlight-current-row @row-click="handleRowClick" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="合同编号" align="center" show-overflow-tooltip prop="contractNo" />
      <el-table-column label="合同名称" align="center" show-overflow-tooltip prop="contractName" />
      <el-table-column label="费率类型" align="center" prop="saleBuyType" />
      <el-table-column label="托运人" align="center" show-overflow-tooltip prop="customerName" />
      <el-table-column label="承运人" align="center" prop="carrierName" />
    </el-table>

    <!-- 分页 -->
    <pagination v-show="page.total>0" :total="page.total" :page.sync="page.current" :limit.sync="page.pageSize" @pagination="getList" />
    <contract-detail v-if="rowId && detailVisible" :id="rowId" class="detail-view" @close="handleDetailClose" @callback="handleQuery" />
    <contract-save v-if="addVisible" @callback="handleQuery" @close="addVisible = false" style="background-color: rgb(245, 246, 249,0.5);" />
  </div>
</template>

<script>
import ListMixin from '@/mixins/List'
import ConContractApi from '@/api/contract/ConContractApi'
import ContractDetail from './ContractDetail.vue'
import ContractSave from './ContractSave.vue'

export default {
  name: 'ContractList',
  components: {
    ContractDetail,
    ContractSave
  },
  mixins: [ListMixin],
  data() {
    return {
      options: {
        customerTypeOptions: [],
        sysYnTypeOptions: this.$constant.sysYnTypeOptions
      },
      queryParams: {
        contractCode: null,
        contractName: null,
        isValid: this.$constant.Y
      },
      page: {
        current: 1,
        pageSize: 10,
        total: 0,
        records: []
      },
      loading: true,
      searchVisible: true,
      multipleSelection: [],
      isSingle: true,
      isMultiple: true
    }
  },
  created() {
    this.setApi(ConContractApi)
    this.handleQuery()
    this.loadOptions()
  },
  methods: {
    loadOptions() {
    },
    handleRowClick(row, column, event) {
      if (column.type === 'selection') {
        return
      }
      if (column.property === 'contractNo') {
        this.rowId = row.id
        this.detailVisible = true
      } else {
        this.detailVisible = false
      }
    },
    cellStyle({ row, column, rowIndex, columnIndex }) {
      if (column.property === 'contractNo') {
        return {
          color: '#3E84E9',
          cursor: 'pointer'
        }
      } else {
        return ''
      }
    },
    resetQuery() {
      this.page.current = 1
      this.resetForm('queryForm')
      this.handleQuery()
    }
  }
}
</script>
